package com.itheima.net;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.Socket;
import java.util.Objects;

public class chat implements Runnable{
    private Socket socket;
    public chat(Socket socket) {
        this.socket = socket;
    }

    @Override
    public void run() {
        try (InputStream in = socket.getInputStream();

             BufferedReader br = new BufferedReader(new InputStreamReader(in));
        ){
            while (true){

                String msg = br.readLine();
                System.out.println("客户端说：" + msg);
                if (Objects.equals(msg, "886")){
                    System.out.println("客户端退出了聊天室"+socket.getInetAddress().getHostAddress());
                    break;
                }
            }


        } catch (Exception e) {
            System.out.println("客户端强制退出！");
        }
    }
}
